//
//  CCYWelcomeView.m
//  模拟-百思不得姐
//
//  Created by 程春玉 on 16/8/8.
//  Copyright © 2016年 chunyu. All rights reserved.
//

#import "CCYWelcomeView.h"

@implementation CCYWelcomeView


+ (void)show
{
    NSString *key = @"CFBundleShortVersionString";
    // 得到系统版本号
    NSString *currentVersion = [[NSBundle mainBundle] infoDictionary][key];
    // 得到沙盒中的版本号
    NSString *pathVersion = [[NSUserDefaults standardUserDefaults] stringForKey:key];
    if (![currentVersion isEqualToString:pathVersion]) {
        UIWindow *window = [[UIApplication sharedApplication] keyWindow];
        CCYWelcomeView *welcome = [self loadNib];
        welcome.frame = window.frame;
        [window addSubview:welcome];
        // 将沙盒中的版本号更新到系统版本号
        [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:key];
        // 此方法是立即同步，不写的话，版本号更新不知道什么时候才会存进去
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}


- (IBAction)knowBtn:(UIButton *)sender {
    [self removeFromSuperview];
}


+ (instancetype)loadNib
{
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
}

@end
